package com.zack.dao;

import com.zack.domain.User;
import com.zack.util.JDBCUtils;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

/**
 * @author zack
 * @create 2019-08-06-17:02
 */
public class UserDao {
    //声明JDBC对象公用
    private JdbcTemplate template = new JdbcTemplate(JDBCUtils.getDataSource());

    /**
     * 登录方法
     *
     * @return
     */
    public User login(User loginuser) {
        try {
            //1.编写sql
            String sql = "select *from user where username=? and password=?";
            //2.调用query方法
            User user = template.queryForObject(sql, new BeanPropertyRowMapper<User>(User.class), loginuser.getUsername(), loginuser.getPassword());

            return user;
        } catch (DataAccessException e) {
            e.printStackTrace();
            return null;
        }
    }
}
